package com.uni.web.util;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.springframework.util.ResourceUtils;

import com.github.wxpay.sdk.WXPayConfig;

public class WxConfig implements WXPayConfig{
	
	private static byte[] certData;
	
	static {
		 String certPath = "classpath:cert/apiclient_cert.p12";
//        String certPath = "/opt/java/wx-pay/apiclient_cert.p12";
        try {
            File file = ResourceUtils.getFile(certPath);
            InputStream certStream = new FileInputStream(file);
            WxConfig.certData = new byte[(int) file.length()];
            System.out.println(WxConfig.certData.toString());
            certStream.read(WxConfig.certData);
            certStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
	}

	@Override
	public String getAppID() {
		return WechatUtil.appid;
	}

	@Override
	public InputStream getCertStream() {
		ByteArrayInputStream certBis = new ByteArrayInputStream(WxConfig.certData);
		return certBis;
	}

	@Override
	public int getHttpConnectTimeoutMs() {
		return 8000;
	}

	@Override
	public int getHttpReadTimeoutMs() {
		return 10000;
	}

	@Override
	public String getKey() {
		return WechatUtil.key;
	}

	@Override
	public String getMchID() {
		return WechatUtil.mchId;
	}

}
